import * as types from '../mutation-types'
import {getUserInfo} from 'api/user-info'

const state = {
  selfInfo: {}
}
const getters = {
  selfInfo: state => state.selfInfo
}
const actions = {
  getSelfInfo({commit}, {loginname}) {
    return getUserInfo(loginname).then((res) => {
      if (res.success === false) {
        return res
      } else {
        commit(types.SET_SELF_INFO, res.data)
        return res
      }
    })
  }
}
const mutations = {
  [types.SET_SELF_INFO](state, value) {
    state.selfInfo = value
  }
}

export default {
  state,
  getters,
  mutations,
  actions
}
